package com.xms.security.service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xms.core.module.ModuleCollection;
import com.xms.module.entity.Module;
import com.xms.security.data.ResourceownerMapper;
import com.xms.security.entity.ResourceOwner;
import com.xms.utils.CollectionUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author migo
 * @since 2021-09-04
 */
@Service
public class ResourceOwnerService extends ServiceImpl<ResourceownerMapper, ResourceOwner> implements IResourceOwnerService {

    private static List<ResourceOwner> _all;

    @Autowired
    public List<ResourceOwner> all() {
        if (_all == null) {
            _all = super.list();
            if (CollectionUtil.notEmpty(ModuleCollection.getModules())) {
                _all.forEach(x -> {
                    Module mm = ModuleCollection.getModules().stream().filter(m -> m.getName().equalsIgnoreCase(x.getModulename())).findFirst().orElse(null);
                    if (mm != null) x.setModulelocalizedname(mm.getLocalizedname());
                });
            }
        }
        return _all;
    }
}
